diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-11 09:31:51 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-11 09:31:51 +0700 |
| commit | 7cdb4cef31577818682b63ccbe01b53dd08a9207 (patch) | |
| tree | 931aaec82155bdc4af89b5b5b5b78de4980311c1 /src/pages/sitemap/searchkey/[page].js | |
| parent | 95b27ddb0604fbb4fae130f2d80e5ee2aec6d0fc (diff) | |
<Miqdad> sitemap done
Diffstat (limited to 'src/pages/sitemap/searchkey/[page].js')
| -rw-r--r-- | src/pages/sitemap/searchkey/[page].js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pages/sitemap/searchkey/[page].js b/src/pages/sitemap/searchkey/[page].js new file mode 100644 index 00000000..cee53f5e --- /dev/null +++ b/src/pages/sitemap/searchkey/[page].js @@ -0,0 +1,42 @@ +import productSearchApi from '@/lib/product/api/productSearchApi'; +import { create } from 'xmlbuilder'; +import _ from 'lodash-contrib'; +import { createSlug } from '@/core/utils/slug'; +import axios from 'axios'; + +export async function getServerSideProps({ query, res }) { + // const baseUrl = process.env.SELF_HOST + '/shop/product/'; + const { page } = query; + const limit = 500; + const keywords = await axios( + `${ + process.env.NEXT_PUBLIC_SELF_HOST + }/api/shop/searchkey?limit=${limit}&page=${page.replace('.xml', '')}&all=1` + ); + + const sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ); + + const date = new Date(); + // const date = '2025-10-30'; + keywords.data.response.docs.forEach((product) => { + const url = sitemap.ele('url'); + const loc = product.url_s; + url.ele('loc', loc); + url.ele('lastmod', date.toISOString().slice(0, 10)); + url.ele('changefreq', 'daily'); + url.ele('priority', '0.8'); + }); + + res.setHeader('Content-Type', 'text/xml'); + res.write(sitemap.end()); + res.end(); + + return { props: {} }; +} + +export default function SitemapProducts() { + return null; +} |
